/****************************************************************************** ** Functions by Derrick Sobodash ** http://www.cinnamonpirate.com/ ** Submitted to ROM Hacking.net on July 3, 2006 ******************************************************************************/ /****************************************************************************** ** bmp2bpp() ******************************************************************************* ** syntax: string bmp2bpp(string bitmap, int t_width, int t_height[, ** int rows, int cols]) ******************************************************************************* ** Transforms bitmap from linear bitmap data to tile-based bitplane data. ** Tiles will be sized as t_widthxt_height. If rows and cols aren't ** specified, both will default to 16. The result will need to be further ** processed if you need to split apart color data. ******************************************************************************/ function bmp2bpp($bitmap, $t_width, $t_height, $rows = 16, $cols = 16) { if($t_width == null || $bitmap == null || $t_height == null) die("Error: bmp2bpp(): Requires at least three non-null arguments\n\n"); $ptr = 0; $bitplane = ""; for($k = 0; $k < $rows; $k ++) { for($i = 0; $i < $t_height; $i ++) { for($z = 0; $z < $cols; $z ++) { $tile[$z][$i] = substr($bitmap, $ptr, $t_width); $ptr += $t_width; } } for($z = $cols - 1; $z > -1; $z --) { for($i = 0; $i < $t_height; $i ++) $bitplane .= strrev($tile[$z][$i]); } unset($tile); } return($bitplane); } /****************************************************************************** ** bpp2bmp() ******************************************************************************* ** syntax: string bpp2bmp(string bitplane, int t_width, int t_height[, ** int rows, int cols]) ******************************************************************************* ** Transforms bitplane from tile-based bitplane data to linear bitmap data. ** Tiles will be sized as t_widthxt_height. If rows and cols aren't ** specified, both will default to 16. The resulting pixel stream will need ** to be further processed into a valid graphic format. ******************************************************************************/ function bpp2bmp($bitplane, $t_width, $t_height, $rows = 16, $cols = 16) { if($t_width == null || $bitplane == null || $t_height == null) die("Error: bpp2bmp(): Requires at least three non-null arguments\n\n"); $bitmap = ""; $ptr = 0; for($k = 0; $k < $rows; $k ++) { for($i = 0; $i < $cols; $i ++) { for($z = 0; $z < $t_height; $z ++) { $line[$i][$z] = substr($bitplane, $ptr, $t_width); $ptr = $ptr + $t_width; } } for($z = 0; $z < $t_height; $z ++) { for($i = $cols - 1; $i > -1; $i --) $bitmap .= strrev($line[$i][$z]); } } return($bitmap); }